package com.zjy.heath_ms.controller;

import com.zjy.heath_ms.entity.Result;
import com.zjy.heath_ms.pojo.OrderSetting;
import com.zjy.heath_ms.service.OrderSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 项目名 heath_ms
 * 类名  OrderSettingController
 * 作者 lzq
 * 创建时间  2025/5/25 11:21
 */
@RestController
@RequestMapping("/orderSetting")
public class OrderSettingController {


    @Autowired
    private OrderSettingService orderSettingService;

    /**
     * 根据年和月分获取预约设置
     * @param year
     * @param month
     * @return
     */
    @GetMapping
    public Result getOrderSettingByYearMonth(Integer year, Integer month){
        List<OrderSetting> orderSettings = orderSettingService.getOrderSettingByYearMonth(year, month);
        return Result.buildSuccess(orderSettings);
    }
    /**
     * 根据日期编辑预约设置
     */
    @PutMapping
    public Result editOrderSettingByDate(@RequestBody OrderSetting orderSetting){
        boolean res = orderSettingService.editOrderNumberByDate(orderSetting);
        return res ? Result.buildSuccess() : Result.buildFail();

    }

    /**
     * 批量上传预约设置
     */
    @PostMapping("/upload")
    public Result uploadExcel(MultipartFile file) {
        return orderSettingService.upload(file) ?  Result.buildSuccess() : Result.buildFail();
    }
}
